package codetop.greedy;

import java.util.Arrays;

public class Code881 {
    public int numRescueBoats(int[] people, int limit) {
        Arrays.sort(people);
        int ans=0;
        int left=0;
        int right=people.length-1;
        while (left<=right){
            int boat=limit-people[right];
            if (people[left]<=boat)left++;
            right--;
            ans++;
        }
        return ans;
    }
}
